package com.craftplay.dao;

import static org.apache.ibatis.jdbc.SqlBuilder.BEGIN;
import static org.apache.ibatis.jdbc.SqlBuilder.INSERT_INTO;
import static org.apache.ibatis.jdbc.SqlBuilder.SET;
import static org.apache.ibatis.jdbc.SqlBuilder.SQL;
import static org.apache.ibatis.jdbc.SqlBuilder.UPDATE;
import static org.apache.ibatis.jdbc.SqlBuilder.VALUES;
import static org.apache.ibatis.jdbc.SqlBuilder.WHERE;

import com.craftplay.model.Offer;

public class OfferSqlProvider {

    public String insertSelective(Offer record) {
        BEGIN();
        INSERT_INTO("offer");
        
        if (record.getId() != null) {
            VALUES("id", "#{id,jdbcType=INTEGER}");
        }
        
        if (record.getUnitId() != null) {
            VALUES("unit_id", "#{unitId,jdbcType=INTEGER}");
        }
        
        if (record.getOwnerId() != null) {
            VALUES("owner_id", "#{ownerId,jdbcType=INTEGER}");
        }
        
        if (record.getActorId() != null) {
            VALUES("actor_id", "#{actorId,jdbcType=INTEGER}");
        }
        
        if (record.getOfferPrice() != null) {
            VALUES("offer_price", "#{offerPrice,jdbcType=INTEGER}");
        }
        
        if (record.getPlaceProvided() != null) {
            VALUES("place_provided", "#{placeProvided,jdbcType=INTEGER}");
        }
        
        if (record.getPlaceFee() != null) {
            VALUES("place_fee", "#{placeFee,jdbcType=INTEGER}");
        }
        
        if (record.getTool() != null) {
            VALUES("tool", "#{tool,jdbcType=INTEGER}");
        }
        
        if (record.getToolFee() != null) {
            VALUES("tool_fee", "#{toolFee,jdbcType=INTEGER}");
        }
        
        if (record.getTimeLen() != null) {
            VALUES("time_len", "#{timeLen,jdbcType=INTEGER}");
        }
        
        if (record.getLeaveWord() != null) {
            VALUES("leave_word", "#{leaveWord,jdbcType=VARCHAR}");
        }
        
        if (record.getStatus() != null) {
            VALUES("status", "#{status,jdbcType=INTEGER}");
        }
        
        if (record.getCreatedTime() != null) {
            VALUES("created_time", "#{createdTime,jdbcType=TIMESTAMP}");
        }
        
        return SQL();
    }

    public String updateByPrimaryKeySelective(Offer record) {
        BEGIN();
        UPDATE("offer");
        
        if (record.getUnitId() != null) {
            SET("unit_id = #{unitId,jdbcType=INTEGER}");
        }
        
        if (record.getOwnerId() != null) {
            SET("owner_id = #{ownerId,jdbcType=INTEGER}");
        }
        
        if (record.getActorId() != null) {
            SET("actor_id = #{actorId,jdbcType=INTEGER}");
        }
        
        if (record.getOfferPrice() != null) {
            SET("offer_price = #{offerPrice,jdbcType=INTEGER}");
        }
        
        if (record.getPlaceProvided() != null) {
            SET("place_provided = #{placeProvided,jdbcType=INTEGER}");
        }
        
        if (record.getPlaceFee() != null) {
            SET("place_fee = #{placeFee,jdbcType=INTEGER}");
        }
        
        if (record.getTool() != null) {
            SET("tool = #{tool,jdbcType=INTEGER}");
        }
        
        if (record.getToolFee() != null) {
            SET("tool_fee = #{toolFee,jdbcType=INTEGER}");
        }
        
        if (record.getTimeLen() != null) {
            SET("time_len = #{timeLen,jdbcType=INTEGER}");
        }
        
        if (record.getLeaveWord() != null) {
            SET("leave_word = #{leaveWord,jdbcType=VARCHAR}");
        }
        
        if (record.getStatus() != null) {
            SET("status = #{status,jdbcType=INTEGER}");
        }
        
        if (record.getCreatedTime() != null) {
            SET("created_time = #{createdTime,jdbcType=TIMESTAMP}");
        }
        
        WHERE("id = #{id,jdbcType=INTEGER}");
        
        return SQL();
    }
}